package com.alg;

/**
 * @author: sun.hongliang
 * @create: 2020/01/02 15:57
 */
public class MyCircularQueue {
    private int first = -1;
    private int[] source;
    private int size;

    public MyCircularQueue(int k) {
        source = new int[k];
    }

    public boolean enQueue(int value) {
        if (isFull()) {
            return false;
        }
        first = first % source.length;
        source[(first + size + 1) % source.length] = value;
        size++;
        return true;
    }

    public boolean deQueue() {
        if (isEmpty()) return false;
        first++;
        size--;
        return true;
    }

    public int Front() {
        if (size == 0) return -1;
        first = first % source.length;
        return source[first + 1];
    }

    public int Rear() {
        if (size == 0) return -1;
        first = first % source.length;
        return source[(first + size) % source.length];
    }

    public boolean isEmpty() {
        return size <= 0;
    }

    public boolean isFull() {
        return size >= source.length;
    }


    public static void main(String[] args) {
    }

}
